<?
require("config.php");
require("../bin/php-excel.class.php");
$table="cus_info";

if (null==$listfield1) $listfield1 = "code";
if (null==$listfield2) $listfield2 = "username";

$Query = "select id, $listfield1, $listfield2,firstname,lastname,tel,regtime,email,mobile,address,country,sex,birthday,edu,occupation from $table order by id desc   limit 10000 ";

$r = myQuery($Query);

/*header("Content-type:application/vnd.ms-excel;charset=BIG5");  
header("Content-Disposition:filename=customer_info_" . date("Ymd") . ".xls");  

echo "Code\t";
echo "Name\t";
echo "Mobile\t";
echo "Telephone\t";
echo "Email\t";
echo "Address\t";
echo "Country\t";
echo "Sex\t";
echo "Birthday\t";
echo "Education\t";
echo "Occupation\t";
echo "Register Date\t\n";

for ($i=0;$i<count($r);$i++){

echo $r[$i][0] . "\t"; 
echo $r[$i][3].' '.$r[$i][4] . "\t"; 
echo $r[$i][8]."\t";
echo $r[$i][5] . "\t"; 
echo $r[$i][7] . "\t"; 
echo str_replace("\t"," ",str_replace("\n"," ",str_replace("\r"," ",$r[$i][9])))."\t";
echo $r[$i][10]."\t";
echo $r[$i][11]."\t";
echo $r[$i][12]."\t";
echo $r[$i][13]."\t";
echo $r[$i][14]."\t";
echo date('Y-m-d',$r[$i][6]) . "\t\n"; 
}

echo "\n";*/ 

$data[] = array("Code","Name","Mobile","Telephone","Email","Address","Country",
	"Sex","Birthday","Education","Occupation","Register Date");
for ($i=0;$i<count($r);$i++){
	$data [] = array(
		$r[$i][0],
		$r[$i][3].' '.$r[$i][4],
		$r[$i][8],
		$r[$i][5],
		$r[$i][7],
		str_replace("\t"," ",str_replace("\n"," ",str_replace("\r"," ",$r[$i][9]))),
		$r[$i][10],
		$r[$i][11],
		$r[$i][12],
		$r[$i][13],
		$r[$i][14],
		date('Y-m-d',$r[$i][6])
	);
}
$xls = new Excel_XML('BIG5', false, 'Customers');
$xls->addArray($data);
$filename = "customer_info_".date("Ymd").".xls";
$xls->generateXML($filename);

@mysql_close();
?>


